﻿using MediatR;
using Trace.Infrastructure.Repository;
using Trace.WebApi.Commands;

namespace Trace.WebApi.CommandHandler
{
    public class SignHZTraceCommandHandler : IRequestHandler<SignHZTraceCommands, int>
    {
        private readonly IRepository<Contract.Domain.Contract> repository;

        public SignHZTraceCommandHandler(IRepository<Contract.Domain.Contract> repository)
        {
            this.repository = repository;
        }

        public async Task<int> Handle(SignHZTraceCommands request, CancellationToken cancellationToken)
        {
            var info = await repository.GetAsync(x => x.ContractNumber.Equals(request.ContractNumber));
            info.State = 2;
            info.UpdateDate = DateTime.Now;
            var ind = await repository.UpdateAsync(info);
            return ind;
        }
    }
}
